home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: in2.uu.net!iglou!news
- From: "Abe L. Getchell" <panther@iglou.com>
- Subject: Re: A simple question for all the C++ gurus out there!
- X-Nntp-Posting-Host: dp-2-14.iglou.net
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <31221E91.7817@iglou.com>
- Sender: news@iglou.com (News Administrator)
- Content-Transfer-Encoding: 7bit
- Organization: 3DX Studios
- References: <3120F95F.659@iglou.com> <31210272.29E69549@eiffel.com>
- Mime-Version: 1.0
- Date: Wed, 14 Feb 1996 17:40:33 GMT
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Guus Leeuw jr. wrote:
- >
- > Abe L. Getchell wrote:
- > >
- > > I am trying to write a public member function that will use a private
- > > data member from which it inherited from the base class. This won't compile.
- > > It gives me an error message like "A::a private data member not accessible in
- > > class B". Why won't this work if the prvate data member being inherited from
- > > the base class A be a private data member of the derived class?
- >
- > When you derive from a class you will only be able to access the public and protected
- > members of that [base] class.
- >
- > So if your classes are like
- >
- > class A
- > {
- > public:
- > A();
- > ~A();
- > protected:
- > int b;
- > private:
- > int a;
- > }
- >
- > class B: public A
- > {
- > public:
- > B();
- > ~B();
- > void do_something() {cout << b << endl;}
- > }
- >
- > everything'll be just fine.
- >
- > Datamember `A::a' is not accessible from other classes than class A.
- >
- > This scheme is of particular use when the base class has datamembers or member
- > functions which are not to be inherited by derived classes.
- >
- > The protected members, however, will be inherited and thus accessible.
- >
- > Hope this explains,
- > Guus Leeuw jr.
-
- Thank you very much for the help! After many nice replies in the group
- ( and one not so nice one in mail :/ ) I finally understand it. :) Thank you
- for your help...
-
- Abe L. Getchell
-